/*
day260
2020.5.14
*/

#include<cstdlib> 
using namespace std;
struct TreeNode {
    int val;
    TreeNode *left;
    TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
public:
    int sumEvenGrandparent(TreeNode* root) {
		int sum=0;
		
		if(!root)
		{
			return sum;
		}
		
		if(root->val%2==0)
		{
			sum+=grandChildSum(root);
		}
		
		sum += ( sumEvenGrandparent(root->left) + sumEvenGrandparent(root->right) );
		
		return sum;
    }
    
    
    int grandChildSum(TreeNode *root)
	{
		int sum=0;
		if(root->left)
		{
			if(root->left->left)
			{
				sum+=root->left->left->val;
			}
			
			if(root->left->right)
			{
				sum+=root->left->right->val;
			}
		}
		
		if(root->right)
		{
			if(root->right->left)
			{
				sum+=root->right->left->val;
			}
			
			if(root->right->right)
			{
				sum+=root->right->right->val;
			}
		}
		
		return sum;
	} 
};

int main()
{
	return 0;
}
